﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace yule.Common.Cache
{
    /// <summary>
    /// AspNet缓存策略
    /// </summary>
    internal class AspNetCacheStrategy : ICacheStrategy
    {
        private System.Web.Caching.Cache _cache = null;

        private System.Web.Caching.Cache Cache
        {
            get
            {
                if (this._cache == null && System.Web.HttpContext.Current != null)
                {
                    this._cache = System.Web.HttpContext.Current.Cache;
                }
                return this._cache;
            }
        }


        #region ICacheStrategy 成员

        public bool Set<T>(string key, T obj) where T : class
        {
            if (this.Cache != null)
            {
                this.Cache[key] = obj;
                return true;
            }
            else
            {
                return false;
            }
        }

        public T Get<T>(string key) where T : class
        {
            T t = default(T);
            if (this.Cache != null)
            {
                t = (T)this.Cache[key];
            }
            return t;
        }


        public bool Remove<T>(string key) where T : class
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ICacheStrategy 成员


        public IList<T> Get<T>() where T : class
        {
            throw new NotImplementedException();
        }

        public bool Remove<T>() where T : class
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}